#include "gtkcssshorthandpropertyprivate.h"
+#include "gtkintl.h"
+
+enum {
+ PROP_0,
+ PROP_SUBPROPERTIES,
+};
+
G_DEFINE_TYPE (GtkCssShorthandProperty, _gtk_css_shorthand_property, GTK_TYPE_STYLE_PROPERTY)
+static void
+gtk_css_shorthand_property_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ GtkCssShorthandProperty *property = GTK_CSS_SHORTHAND_PROPERTY (object);
+ const char **subproperties;
+ guint i;
+
+ switch (prop_id)
+ {
+ case PROP_SUBPROPERTIES:
+ subproperties = g_value_get_boxed (value);
+ g_assert (subproperties);
+ for (i = 0; subproperties[i] != NULL; i++)
+ {
+ GtkStyleProperty *subproperty = _gtk_style_property_lookup (subproperties[i]);
+ g_assert (GTK_IS_CSS_STYLE_PROPERTY (subproperty));
+ g_ptr_array_add (property->subproperties, subproperty);
+ }
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
static void
_gtk_css_shorthand_property_class_init (GtkCssShorthandPropertyClass *klass)
{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->set_property = gtk_css_shorthand_property_set_property;
+
+ g_object_class_install_property (object_class,
+ PROP_SUBPROPERTIES,
+ g_param_spec_boxed ("subproperties",
+ P_("Subproperties"),
+ P_("The list of subproperties"),
+ G_TYPE_STRV,
+ G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
}
static void
_gtk_css_shorthand_property_init (GtkCssShorthandProperty *shorthand)
{
+ shorthand->subproperties = g_ptr_array_new_with_free_func (g_object_unref);
+}
+
+GtkCssStyleProperty *
+_gtk_css_shorthand_property_get_subproperty (GtkCssShorthandProperty *shorthand,
+ guint property)
+{
+ g_return_val_if_fail (GTK_IS_CSS_SHORTHAND_PROPERTY (shorthand), NULL);
+ g_return_val_if_fail (property < shorthand->subproperties->len, NULL);
+
+ return g_ptr_array_index (shorthand->subproperties, property);
+}
+
+guint
+_gtk_css_shorthand_property_get_n_subproperties (GtkCssShorthandProperty *shorthand)
+{
+ g_return_val_if_fail (GTK_IS_CSS_SHORTHAND_PROPERTY (shorthand), 0);
+
+ return shorthand->subproperties->len;
}
static void
_gtk_css_shorthand_property_register (GParamSpec *pspec,
+ const char **subproperties,
GtkStylePropertyFlags flags,
GtkStylePropertyParser property_parse_func,
GtkStyleUnpackFunc unpack_func,
node = g_object_new (GTK_TYPE_CSS_SHORTHAND_PROPERTY,
"name", pspec->name,
+ "subproperties", subproperties,
NULL);
node->flags = flags;
void
_gtk_css_shorthand_property_init_properties (void)
{
+ const char *font_subproperties[] = { "font-family", "font-style", "font-variant", "font-weight", "font-size", NULL };
+ const char *margin_subproperties[] = { "margin-top", "margin-right", "margin-bottom", "margin-left", NULL };
+ const char *padding_subproperties[] = { "padding-top", "padding-right", "padding-bottom", "padding-left", NULL };
+ const char *border_width_subproperties[] = { "border-top-width", "border-right-width", "border-bottom-width", "border-left-width", NULL };
+ const char *border_radius_subproperties[] = { "border-top-left-radius", "border-top-right-radius",
+ "border-bottom-right-radius", "border-bottom-left-radius", NULL };
+ const char *border_color_subproperties[] = { "border-top-color", "border-right-color", "border-bottom-color", "border-left-color", NULL };
+ const char *border_image_subproperties[] = { "border-image-source", "border-image-slice", "border-image-width", "border-image-repeat", NULL };
+
_gtk_css_shorthand_property_register (g_param_spec_boxed ("font",
"Font Description",
"Font Description",
PANGO_TYPE_FONT_DESCRIPTION, 0),
+ font_subproperties,
GTK_STYLE_PROPERTY_INHERIT,
NULL,
unpack_font_description,
"Margin",
"Margin",
GTK_TYPE_BORDER, 0),
+ margin_subproperties,
0,
NULL,
unpack_margin,
"Padding",
"Padding",
GTK_TYPE_BORDER, 0),
+ padding_subproperties,
0,
NULL,
unpack_padding,
"Border width",
"Border width, in pixels",
GTK_TYPE_BORDER, 0),
+ border_width_subproperties,
0,
NULL,
unpack_border_width,
"Border radius",
"Border radius, in pixels",
0, G_MAXINT, 0, 0),
+ border_radius_subproperties,
0,
NULL,
unpack_border_radius,
"Border color",
"Border color",
GDK_TYPE_RGBA, 0),
+ border_color_subproperties,
0,
NULL,
unpack_border_color,
"Border Image",
"Border Image",
GTK_TYPE_BORDER_IMAGE, 0),
+ border_image_subproperties,
0,
NULL,
_gtk_border_image_unpack,
#include <glib-object.h>
+#include "gtk/gtkcssparserprivate.h"
+#include "gtk/gtkcssstylepropertyprivate.h"
#include "gtk/gtkstylepropertyprivate.h"
G_BEGIN_DECLS
struct _GtkCssShorthandProperty
{
GtkStyleProperty parent;
+
+ GPtrArray *subproperties;
};
struct _GtkCssShorthandPropertyClass
GType _gtk_css_shorthand_property_get_type (void) G_GNUC_CONST;
+GtkCssStyleProperty * _gtk_css_shorthand_property_get_subproperty (GtkCssShorthandProperty *shorthand,
+ guint property);
+guint _gtk_css_shorthand_property_get_n_subproperties (GtkCssShorthandProperty *shorthand);
+
G_END_DECLS